#ifndef CENTER_DETECTOR_HPP
#define CENTER_DETECTOR_HPP

#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <geometry_msgs/msg/point_stamped.hpp>
#include <std_msgs/msg/header.hpp> 
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <memory>
#include <tf2_ros/static_transform_broadcaster.h>
#include <tf2_ros/transform_broadcaster.h>
#include <std_msgs/msg/string.hpp>
#include "center_detection/detection_manager.hpp"
#include "center_detection/barrel_detector.hpp"
#include "center_detection/cover_detector.hpp"
#include "center_detection/neutron_detector.hpp"
#include "center_detection/center_json.hpp"



namespace center_detection {

    class CenterDetector : public rclcpp::Node,  public std::enable_shared_from_this<CenterDetector>
    {

    public:
    
        CenterDetector();


    private:

        void declare_parameters();
        void init_components();
        void setup_ros_interface();

        void cloud_callback(const sensor_msgs::msg::PointCloud2::SharedPtr msg);
        void perform_detection(const pcl::PointCloud<pcl::PointXYZI>::Ptr& cloud);
        void detection_mode_callback(const std_msgs::msg::String::SharedPtr msg);

        // 获取检测模式函数
    

        //ROS接口
        rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr cloud_sub_;
        rclcpp::Subscription<std_msgs::msg::String>::SharedPtr detection_mode_sub_;

        rclcpp::Publisher<geometry_msgs::msg::PointStamped>::SharedPtr pub_barrel_center_;
        rclcpp::Publisher<geometry_msgs::msg::PointStamped>::SharedPtr pub_cover_center_;
        rclcpp::Publisher<geometry_msgs::msg::PointStamped>::SharedPtr pub_neutron_center_;

        rclcpp::Publisher<std_msgs::msg::String>::SharedPtr pub_center_json_;


        //处理接口
        std::unique_ptr<DetectionManager> detection_manager_;

        // 检测器模式选择
        std::string detection_mode_;

        // 互斥锁保护共享变量
        std::mutex detection_mode_mutex_;
    

        // 新增json和string发布成员
        CenterJsonConverter json_coord_;
        std_msgs::msg::String json_msg_;

        

    };


}

#endif